package com.star.news.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.star.core.base.BaseController;
import com.star.news.dto.NewsCollectSaveDTO;
import com.star.news.dto.NewsPageWebDTO;
import com.star.news.entity.News;
import com.star.news.service.NewsCollectService;
import com.star.news.service.NewsService;
import com.star.news.vo.NewsDetailWebVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lintianyi
 * @version 1.0
 * @date 2024/6/25 17:19
 */
@RestController
@RequestMapping("/web/news")
public class NewsWebController extends BaseController {
    @Resource
    private NewsService newsService;
    @Resource
    private NewsCollectService newsCollectService;

    /**
     * 列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/pageWeb")
    public IPage<News> pageWeb(NewsPageWebDTO dto) {
        return newsService.pageWeb(dto);
    }

    /**
     * web端获取按最新时间展示前三个新闻列表
     *
     * @return {@link List}<{@link News}>
     */
    @GetMapping("/listWebTop3")
    public List<News> listWebTop3() {
        return newsService.listWebTop3();
    }


    /**
     * 获取详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public NewsDetailWebVO getDetailWeb(@PathVariable Long id) {
        return newsService.getDetailWeb(id);
    }

    /**
     * 收藏新闻
     *
     * @param id
     */
    @PostMapping("/updatePageView")
    public void updatePageView(@PathVariable Long id) {
        newsService.updatePageView(id);
    }


    /**
     * 收藏新闻
     *
     * @param dto
     */
    @PostMapping("/saveNewsCollect")
    public void saveNewsCollect(NewsCollectSaveDTO dto) {
        newsCollectService.save(dto);
    }

    /**
     * 取消收藏
     *
     * @param id
     * @return
     */
    @GetMapping("/cancelNewsCollect")
    public void cancelNewsCollect(@PathVariable Long id) {
        newsCollectService.cancelNewsCollect(id);
    }
}
